import requests
import os
path =r"D:\pycharm_pro2019.3.1\pycharm_pro_jb51--2019.3.1\pycharm-professional\PyCharm 2019.3.1\test"
if not os.path.isdir(path):
        os.mkdir(path)
with open('imgbp2to5.txt', 'r', encoding='utf-8') as f:
    img_txt = f.read()
    print(img_txt)
    list0 = img_txt.split('\n'  )  # 形成列表
    print(len(list0))
    list0.remove(list0[-1])
del list0[0:4000]
print(len(list0))
count = 4021
for i in list0:
    headers4 = {
        'User-Agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 71.0.3578.98Safari / 537.36',
        'Referer': i,
        'Connection': 'close'
    }
    print(i)
    try:
        r = requests.get(i ,headers = headers4 ,timeout = 3)
        with open(
                r'D:\pycharm_pro2019.3.1\pycharm_pro_jb51--2019.3.1\pycharm-professional\PyCharm 2019.3.1\1\%s.jpg' % count,
                'ab') as f2:
            f2.write(r.content)
        count += 1
    except Exception as e:
        pass